/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ui.guiComponents;


import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import Ui.guiComponents.SetShips;

/**
 *
 * @author Elya
 */
public class Grid extends JPanel{
    

    private  JButton[][] matrix;

    ImageIcon waterIcon = new ImageIcon(getClass().getResource("/Ui/guiComponents/images/water.gif"));
    ImageIcon targetIcon = new ImageIcon(getClass().getResource("/Ui/guiComponents/images/target.gif"));
            
    public Grid(){
        

        //this.setBackground(new java.awt.Color(83, 138, 219));
        this.setVisible(true);
        matrix= new JButton[10][10];
        setLayout(new GridLayout(10,10));

        
        
     
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){

                matrix[i][j]=new JButton(waterIcon);
                add(matrix[i][j]);

            }
        }


        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                    matrix[i][j].addActionListener(new ButtonListener());

            }
        }

    }
    
    
    class ButtonListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            
        if ("Aircraft Carrier".contentEquals(SetShips.clickedBoatName) || "Battleship".contentEquals(SetShips.clickedBoatName) || "Submarine".contentEquals(SetShips.clickedBoatName) || "Destroyer".contentEquals(SetShips.clickedBoatName) || "Cruiser".contentEquals(SetShips.clickedBoatName) ){


            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                
                matrix[i][j].setIcon(waterIcon);

            }
        }
        JButton o = (JButton) e.getSource();
        o.setIcon(targetIcon);

        }
        }
    }
    
}




